Skip to content

fix: android - Pinch gesture handler when one finger is lifted #1799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

intergalacticspacehighway
Copy link

@intergalacticspacehighway intergalacticspacehighway commented Jan 2, 2022

Description

I agree with the notion of preserving the platform behaviour on iOS but in case of android there's no native pinch handler and some custom logic is already there in place, so I am not sure what behavior is correct. I am not sure whether this PR should be merged 😅

Approach

  • End the handler on ACTION_UP. i.e. both fingers are lifted.
  • Do not fire scale detector on ACTION_POINTER_UP. Read more in the comment

Test plan

  • We can test it with the below snippet. Pinch handler will only move to end state when both the fingers are lifted.
  • This gist can also be tested. With the changes in this PR, the gist code will run same in both the platforms.
const handler = useAnimatedGestureHandler<PinchGestureHandlerGestureEvent>({
    onActive(e) {
      console.log("Active")
    },
    onEnd(e) {
      console.log("Ended")
    }
});


// Attach the handler to PinchGestureHandler
<PinchGestureHandler onGestureEvent={handler}>
      <Animated.View
        style={{ height: 300, width: 300, backgroundColor: "pink" }}
      />
</PinchGestureHandler>

if (event.actionMasked == MotionEvent.ACTION_POINTER_UP) {
activePointers -= 1

if(event.actionMasked != MotionEvent.ACTION_POINTER_UP){
Copy link
Author

@intergalacticspacehighway intergalacticspacehighway Jan 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This surely appears weird, but I am not sure If there's a better way to achieve this. This is done due to the below scenario.

User has 2 fingers and performing pinch -> One finger is lifted -> ACTION_POINTER_UP is fired -> event.pointerCount is still 2 -> scale detector sets the focal values to single finger -> the event received has new focus but the pointer count is still 2.

However, this again makes it consistent with iOS. iOS Pinch handler doesn't send events in case of a finger is lifted. Only when a single pointer is moved, it starts sending the event. (practically tested, it would be great if someone can find it documented somewhere)

@intergalacticspacehighway intergalacticspacehighway changed the title Fix/android pinch one finger fix: android - Pinch gesture handler when one finger is lifted Jan 2, 2022
@intergalacticspacehighway
Copy link
Author

Closing in favor of #1800

@intergalacticspacehighway intergalacticspacehighway deleted the fix/android-pinch-one-finger branch January 3, 2022 04:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant